package com.husky.easyexcle.controller;

import com.husky.easyexcle.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * @author huanfuan
 * @date 2023/5/26 16:58
 */

@RestController
@Slf4j
public class EnvFileController {


    @Autowired
    private ExcelService excelServiceImpl;


    /**
     *B. 导入作业流_作业.xlsx文件生成env作业流_作业.xlsx
     *
     * 读取envFile文件
     * @return
     * @throws IOException
     */
    @PostMapping("readEnvFile/data")
    public void readEnvFile(MultipartFile file) {
        log.info("读取上传Excel开始。file={}");
        try {
            excelServiceImpl.readEnvFile(file);
            log.info("list={}");
        }catch (Exception e){
            log.error("读取上传Excel异常。Exception={}",e);
        }

    }




    /**
     * D.导入env作业流_作业.xlsx生成作业流_作业依赖.xlsx
     *
     * 迁移任务依赖系统对象
     *  * @author huanfuan
     * @return
     * @throws IOException
     */
    @PostMapping("taskDep/data")
    public void taskDep(MultipartFile file) {
        log.info("读取上传Excel开始。file={}");
        try {
            excelServiceImpl.taskDep(file);
            log.info("list={}");
        }catch (Exception e){
            log.error("读取上传Excel异常。Exception={}",e);
        }

    }



    /**
     * 迁移任务依赖系统对象
     *  * @author huanfuan
     * @return
     * @throws IOException
     */
    @PostMapping("reaDepFile/data")
    public void reaDepFile(MultipartFile file) {
        log.info("读取上传Excel开始。file={}");
        try {
            excelServiceImpl.reaDepFile(file);
            log.info("list={}");
        }catch (Exception e){
            log.error("读取上传Excel异常。Exception={}",e);
        }

    }


    @GetMapping("/export")
    public ResponseEntity<byte[]> exportExcel(MultipartFile file) throws Exception {

        return excelServiceImpl.readNewExcelVatInvoiceData(file);
    }



}
